package 剑指offer;

/**
 * @description:
 * @author: ywk
 * @date: 2021-03-13
 */
public class 字符串乘法 {
    static String multipy(String num1, String num2) {
        int m = num1.length(), n = num2.length();
        int[] arr = new int[m + n];
        for (int i = m - 1; i >= 0; i--) {
            for (int j = n - 1; j >= 0; j--) {
                int mul = (num1.charAt(i) - '0') * (num2.charAt(j) - '0');
                int p1 = i + j, p2 = i + j + 1;
                int sum = mul + arr[p2];
                arr[p2] = sum % 10;
                arr[p1] += sum / 10;
            }
        }
        int i = 0;
        while (i < arr.length && arr[i] == 0) {
            i++;
        }
        String str = "";
        for (; i < arr.length; i++) {
            str = str + arr[i];
        }
        return str.length() == 0 ? "0" : str;
    }

    public static void main(String[] args) {
        System.out.println(multipy("100", "100"));
    }
}
